home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 December / PCWorld_2005-12_cd.bin / software / temacd / tiny / tpf-6[1].5.126.exe / Tiny Firewall 2005.msi / webui.dll / FIREWALL / FWN-SDBFNCS.JS < prev    next >
Encoding:
Text (UTF-16)  |  2005-08-17  |  79.1 KB  |  1,159 lines

  1. /*//////////////////////////////////////////////////////////////////////
  2. Filename:          fwn-sdbfncs.js
  3. Company Name:      Computer Associates International, Inc.
  4. Legal Copyright: Copyright (c) Computer Associates International, Inc.
  5. Author:          Ales Novak
  6. Product:          Tiny Firewall
  7. Description:      javascript code to access active FW db through XMLSecDBParser COM iface
  8. ///////////////////////////////////////////////////////////////////////*/
  9.  
  10. // requires sdb-consts.js + sdb-msgs.js + tools.js
  11.  
  12. ///////////////////////////////////////////////////////////////////////
  13. // getRuleList - internal function
  14. function FW_getRuleList( bUseClientParser, bIsRoutedRule )
  15. {
  16.     if ( parseBoolean(bIsRoutedRule) == 0 )
  17.     {
  18.         if ( parseBoolean( bUseClientParser ) == 0)
  19.             return external.ServerParser(XM_FW).RuleList;
  20.         else
  21.             return external.ClientParser(XM_FW).RuleList;
  22.     }
  23.     else
  24.         return external.ServerParser(XM_FW).RoutedRuleList;
  25. }
  26.  
  27. ///////////////////////////////////////////////////////////////////////
  28. // getDefinitionList - internal function
  29. function getDefinitionList( bUseClientParser )
  30. {
  31.     return (parseBoolean(bUseClientParser) != 0) ? external.ClientParser(XM_FW).DefinitionList : external.ServerParser(XM_FW).DefinitionList;
  32. }
  33.  
  34. function SaveParser( bUseClientParser)
  35. {
  36.     var parser;
  37.     if ( parseBoolean( bUseClientParser ) == 0)
  38.         parser = external.ServerParser(XM_FW);
  39.     else
  40.         parser = external.ClientParser(XM_FW);
  41.  
  42.     parser.Save(parser.FilePath);
  43. }
  44.  
  45. ///////////////////////////////////////////////////////////////////////
  46. // FW_AddRuleByTransportID
  47. function FW_AddRuleByTransportID( strTransportID, strRemIpAddrID, strRemIpAddr, eZoneMask, 
  48.     strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel, strRuleDescription, bHighPriority, bUseClientParser,
  49.     strUsers, strDayTimeID, strDayTime )
  50. {
  51.     return FW_AddRuleImpl( strTransportID, 0, 0, 0, 0, "", "", strRemIpAddrID, strRemIpAddr, "", "", eZoneMask, 
  52.         strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel, strRuleDescription, bHighPriority, false, false, bUseClientParser,
  53.         strUsers, strDayTimeID, strDayTime );
  54. }
  55.  
  56. ///////////////////////////////////////////////////////////////////////
  57. // FW_AddRuleImpl
  58. //    either strTransportID can be used or combination of eProtocol, iCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts
  59. //    Transport definition => for PROT_ICMP, set eDirection and eICMPType only
  60. //    Transport definition => for PROT_IP => nothing to set
  61. //    Transport definition => for other protocols then TCP/UDP, set iCustomProtocolNum only
  62. //    Rule.ConditionSwitchList is not possible to set via this fnc, use a separate fnc for already existing rule
  63. //    if strRemIpAddrID is set, then strRemIpAddr is ignored. This is valid for strIfaceIpAddr and strDayTime similarly.
  64. //    returns strRuleID or "" on error
  65. //
  66. function FW_AddRuleImpl( strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
  67.     strRemIpAddrID, strRemIpAddr, strLocIpAddrID, strLocIpAddr, eZoneMask, 
  68.     strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel,
  69.     strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser, 
  70.     strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion, 
  71.     bAvoidSavingSDB )
  72. {
  73.     try {
  74.         var ruleList = FW_getRuleList(bUseClientParser, false);
  75.         var newRule = ruleList.CreateRule();
  76.         
  77.         // generate the RuleID => must be unique and must maintain server/client syntax
  78.         newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, parseBoolean(bUseClientParser) == 0 );
  79.         // newRule.RuleIDString is created automatically when newRule.RuleID is set 
  80.         
  81.         newRule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
  82.         newRule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
  83.         newRule.Priority = PRIOR_NORMAL;
  84.         
  85.         if ( !parseBoolean( bUseClientParser ))
  86.             newRule.Priority = ( parseBoolean(bHighPriority) == 1) ? PRIOR_HIGH : PRIOR_LOW;
  87.             
  88.         newRule.Description = strRuleDescription ? strRuleDescription : "";
  89.         
  90.         newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
  91.         newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*"); 
  92.         
  93.         // if object does not exist then create it
  94.         if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID) && !parseBoolean(bUseClientParser))
  95.         {
  96.             var definitionList = getDefinitionList(false);
  97.  
  98.             try
  99.             {
  100.                 var definition = definitionList.Get( strRemIpAddrID );
  101.             }
  102.             catch (e)
  103.             {
  104.                 definition = definitionList.CreateDefinition();
  105.  
  106.                 definition.DefinitionID = strRemIpAddrID;
  107.                 definition.ObjectType = OT_FW_IPADDR;
  108.  
  109.                 definitionList.Insert( definition );
  110.             }
  111.         }
  112.         
  113.         if (strLocIpAddrID || strLocIpAddr)
  114.         {
  115.             newRule.LocIPAddrType = strLocIpAddrID ? RT_DEFINITION : RT_DIRECT;
  116.             newRule.LocIPAddress = strLocIpAddrID ? strLocIpAddrID : (strLocIpAddr ? strLocIpAddr : "*"); 
  117.         }
  118.  
  119.         // if object does not exist then create it
  120.         if ( strLocIpAddrID && isLDAPSupported() && isLDAPName(strLocIpAddrID) && !parseBoolean(bUseClientParser))
  121.         {
  122.             var definitionList = getDefinitionList(false);
  123.  
  124.             try
  125.             {
  126.                 var definition = definitionList.Get( strLocIpAddrID );
  127.             }
  128.             catch (e)
  129.             {
  130.                 definition = definitionList.CreateDefinition();
  131.  
  132.                 definition.DefinitionID = strLocIpAddrID;
  133.                 definition.ObjectType = OT_FW_IPADDR;
  134.  
  135.                 definitionList.Insert( definition );
  136.             }
  137.         }
  138.         
  139.         newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
  140.         if (strTransportID) 
  141.             newRule.TransportID = strTransportID;
  142.         else 
  143.             FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  144.                 
  145.         newRule.Zone = (eZoneMask ? parseInt(eZoneMask) : 0) ? parseInt(eZoneMask) : (ZI_BIT_SAFE | ZI_BIT_DANGEROUS); // ZI_ALL_ZONES goes to exception here
  146.         
  147.         newRule.Account = iAccount;
  148.         
  149.          newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS; 
  150.         newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
  151.         newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0; 
  152.  
  153.         // rarely used fields
  154.         newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
  155.         newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
  156.         // don't really know the TimeOfDay format....
  157.         newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
  158.         newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
  159.         newRule.Assignment = strUsers ? strUsers : "*";  //newRule.Assignment = (window.external.Context ? Assignment : "*");
  160.         newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
  161.         newRule.Preferred = ( parseBoolean(bPreferred) == 1 ) ? true : false;
  162.         newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
  163.         
  164.         var strRuleID = newRule.RuleIDString;
  165.  
  166.         ruleList.Insert(newRule, newRule);
  167.  
  168.         if ( !parseBoolean(bAvoidSavingSDB) )
  169.             SaveParser(bUseClientParser);
  170.  
  171.         return strRuleID;
  172.         
  173.     } catch(e){
  174.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED ); 
  175.         return "";
  176.     }
  177. }
  178.  
  179. function FW_MoveRuleToServerDB( strSrcRuleID, bHighPriority )
  180. {
  181.     try {
  182.         var ruleList = FW_getRuleList(true, false);
  183.         var rule = ruleList.Get(strSrcRuleID);
  184.         
  185.         var ruleList = FW_getRuleList(false, false);
  186.         var newRule = ruleList.CreateRule();
  187.             
  188.         // generate the RuleID => must be unique and must maintain server/client syntax
  189.         newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, true );
  190.         // newRule.RuleIDString is created automatically when newRule.RuleID is set 
  191.         
  192.         newRule.Application = rule.Application;
  193.         newRule.AppType = rule.AppType;
  194.         //newRule.Priority = rule.Priority;
  195.         newRule.Priority = ( bHighPriority ? PRIOR_HIGH : PRIOR_LOW);
  196.         newRule.Description = rule.Description;
  197.         
  198.         newRule.RemIPAddrType = rule.RemIPAddrType;
  199.         newRule.RemIPAddress = rule.RemIPAddress; 
  200.                 
  201.         newRule.LocIPAddrType = rule.LocIPAddrType;
  202.         newRule.LocIPAddress = rule.LocIPAddress; 
  203.         
  204.         ////////////////////////
  205.         newRule.TransportType = rule.TransportType;
  206.         newRule.TransportID = rule.TransportID;
  207.         
  208.         newRule.TransportObject.Content = "";    // assuming used only in Definitions
  209.         newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
  210.         newRule.TransportObject.Direction = rule.TransportObject.Direction;
  211.         
  212.         newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
  213.         newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
  214.         
  215.         newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
  216.         newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
  217.         newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
  218.         newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
  219.         ////////////////////////            
  220.                 
  221.         newRule.Zone = rule.Zone;
  222.         
  223.         newRule.Account = rule.Account;
  224.  
  225.          newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType; 
  226.         newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
  227.         newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult; 
  228.  
  229.         // rarely used fields
  230.         newRule.OutConditionAND = rule.OutConditionAND;
  231.         newRule.OutConditionOR = rule.OutConditionOR;
  232.         
  233.         // don't really know the TimeOfDay format....
  234.         newRule.TimeOfDayType = rule.TimeOfDayType;
  235.         newRule.TimeOfDay = rule.TimeOfDay;
  236.         newRule.Assignment = rule.Assignment;
  237.         newRule.Enabled = rule.Enabled;
  238.         newRule.Preferred = false;//rule.Preferred;
  239.         newRule.OSVersion = rule.OSVersion;
  240.         
  241.         var strRuleID = newRule.RuleIDString;
  242.  
  243.         ruleList.Insert(newRule, newRule);
  244.  
  245.         // delete source rule
  246.         FW_DeleteRule( strSrcRuleID, true );
  247.         
  248.         SaveParser(true);
  249.         SaveParser(false);
  250.  
  251.         return strRuleID;
  252.         
  253.     } catch(e){
  254.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED ); 
  255.         return "";
  256.     }
  257. }
  258.  
  259. function FW_CopyRule( strSrcRuleID, bUseClientParser, bAvoidSavingSDB )
  260. {
  261.     try {
  262.         var ruleList = FW_getRuleList(bUseClientParser, false);
  263.         var newRule = ruleList.CreateRule();
  264.         
  265.         var ruleList = FW_getRuleList(bUseClientParser, false);
  266.         var rule = ruleList.Get(strSrcRuleID);
  267.             
  268.         // generate the RuleID => must be unique and must maintain server/client syntax
  269.         newRule.RuleID = ruleList.GenerateRuleID( OT_FW_TRANS, parseBoolean(bUseClientParser) == 0 );
  270.         // newRule.RuleIDString is created automatically when newRule.RuleID is set 
  271.         
  272.         newRule.Application = rule.Application;
  273.         newRule.AppType = rule.AppType;
  274.         newRule.Priority = rule.Priority;
  275.         newRule.Description = rule.Description;
  276.         
  277.         newRule.RemIPAddrType = rule.RemIPAddrType;
  278.         newRule.RemIPAddress = rule.RemIPAddress; 
  279.                 
  280.         newRule.LocIPAddrType = rule.LocIPAddrType;
  281.         newRule.LocIPAddress = rule.LocIPAddress; 
  282.         
  283.         ////////////////////////
  284.         newRule.TransportType = rule.TransportType;
  285.         newRule.TransportID = rule.TransportID;
  286.         
  287.         newRule.TransportObject.Content = "";    // assuming used only in Definitions
  288.         newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
  289.         newRule.TransportObject.Direction = rule.TransportObject.Direction;
  290.         
  291.         newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
  292.         newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
  293.         
  294.         newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
  295.         newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
  296.         newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
  297.         newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
  298.         ////////////////////////            
  299.                 
  300.         newRule.Zone = rule.Zone;
  301.         
  302.         newRule.Account = rule.Account;
  303.  
  304.          newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType; 
  305.         newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
  306.         newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult; 
  307.  
  308.         // rarely used fields
  309.         newRule.OutConditionAND = rule.OutConditionAND;
  310.         newRule.OutConditionOR = rule.OutConditionOR;
  311.         
  312.         // don't really know the TimeOfDay format....
  313.         newRule.TimeOfDayType = rule.TimeOfDayType;
  314.         newRule.TimeOfDay = rule.TimeOfDay;
  315.         newRule.Assignment = rule.Assignment;
  316.         newRule.Enabled = rule.Enabled;
  317.         newRule.Preferred = rule.Preferred;
  318.         newRule.OSVersion = rule.OSVersion;
  319.         
  320.         var strRuleID = newRule.RuleIDString;
  321.  
  322.         ruleList.Insert(newRule, newRule);
  323.  
  324.         if ( !parseBoolean(bAvoidSavingSDB) )
  325.             SaveParser(bUseClientParser);
  326.  
  327.         return strRuleID;
  328.         
  329.     } catch(e){
  330.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED ); 
  331.         return "";
  332.     }
  333. }
  334.  
  335. function FW_CopyRoutedRule( strSrcRuleID, bAvoidSavingSDB )
  336. {
  337.     try {
  338.         var ruleList = FW_getRuleList(false, true);
  339.         
  340.         var newRule = ruleList.CreateRule();
  341.         var rule = ruleList.Get(strSrcRuleID);
  342.         
  343.         // generate the RuleID => must be unique and must maintain server/client syntax
  344.         newRule.RuleID = ruleList.GenerateRuleID( true );
  345.         // newRule.RuleIDString is created automatically when newRule.RuleID is set 
  346.         
  347.         newRule.Priority = rule.Priority;
  348.         newRule.Description = rule.Description;
  349.         
  350.         newRule.RemIPAddrType = rule.RemIPAddrType;
  351.         newRule.RemIPAddress = rule.RemIPAddress; 
  352.         
  353.         newRule.LANIPAddrType = rule.LANIPAddrType;
  354.         newRule.LANIPAddress = rule.LANIPAddress; 
  355.         
  356.         newRule.IfaceIPAddrType = rule.IfaceIPAddrType;
  357.         newRule.IfaceIPAddress = rule.IfaceIPAddress; 
  358.         
  359.         ////////////////////////
  360.         newRule.TransportType = rule.TransportType;
  361.         newRule.TransportID = rule.TransportID;
  362.         
  363.         newRule.TransportObject.Content = "";    // assuming used only in Definitions
  364.         newRule.TransportObject.Protocol = rule.TransportObject.Protocol;
  365.         newRule.TransportObject.Direction = rule.TransportObject.Direction;
  366.         
  367.         newRule.TransportObject.CustomProtocolNumber = rule.TransportObject.CustomProtocolNumber;
  368.         newRule.TransportObject.ICMPType = rule.TransportObject.ICMPType;
  369.         
  370.         newRule.TransportObject.LocalPortFrom = rule.TransportObject.LocalPortFrom;
  371.         newRule.TransportObject.LocalPortTo = rule.TransportObject.LocalPortTo;
  372.         newRule.TransportObject.RemotePortFrom = rule.TransportObject.RemotePortFrom;
  373.         newRule.TransportObject.RemotePortTo = rule.TransportObject.RemotePortTo;
  374.         ////////////////////////            
  375.                 
  376.          newRule.AccessDescriptor.AccessType = rule.AccessDescriptor.AccessType; 
  377.         newRule.AccessDescriptor.AuditLevel = rule.AccessDescriptor.AuditLevel;
  378.         newRule.AccessDescriptor.AccessResult = rule.AccessDescriptor.AccessResult; 
  379.  
  380.         // rarely used fields
  381.         newRule.OutConditionAND = rule.OutConditionAND;
  382.         newRule.OutConditionOR = rule.OutConditionOR;
  383.         
  384.         // don't really know the TimeOfDay format....
  385.         newRule.TimeOfDayType = rule.TimeOfDayType;
  386.         newRule.TimeOfDay = rule.TimeOfDay;
  387.  
  388.         newRule.Enabled = rule.Enabled;
  389.         newRule.OSVersion = rule.OSVersion;
  390.  
  391.         var strRuleID = newRule.RuleIDString;
  392.         ruleList.Insert(newRule, newRule);
  393.  
  394.         if ( !parseBoolean(bAvoidSavingSDB) )
  395.             SaveParser();
  396.  
  397.         return strRuleID;
  398.         
  399.     } catch(e){
  400.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED ); 
  401.         return "";
  402.     }
  403. }
  404.  
  405. ///////////////////////////////////////////////////////////////////////
  406. // FW_EditRuleImpl
  407. //    either strTransportID can be used or combination of eProtocol, iCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts
  408. //    Transport definition => for PROT_ICMP, set eDirection and eICMPType only
  409. //    Transport definition => for PROT_IP => nothing to set
  410. //    Transport definition => for other protocols then TCP/UDP, set iCustomProtocolNum only
  411. //    Rule.ConditionSwitchList is not possible to set via this fnc, use a separate fnc for already existing rule
  412. //    if strRemIpAddrID is set, then strRemIpAddr is ignored. This is valid for strIfaceIpAddr and strDayTime similarly.
  413. //    returns strRuleID or "" on error
  414. //
  415. function FW_EditRuleImpl( strRuleID, strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
  416.     strRemIpAddrID, strRemIpAddr, strLocIpAddrID, strLocIpAddr, eZoneMask,
  417.     strAppGroupID, strAppLabel, iAccount, iAccessResult, iAuditLevel,
  418.     strRuleDescription, bHighPriority, bPreferred, bDisabled, bUseClientParser,
  419.     strUsers, strDayTimeID, strDayTime, iOutConditionAND, iOutConditionOR, eOSVersion,
  420.     bAvoidSavingSDB )
  421. {
  422.     try {
  423.         var ruleList = FW_getRuleList(bUseClientParser, false);
  424.         var newRule = ruleList.Get(strRuleID);
  425.  
  426.         newRule.Application = strAppGroupID ? strAppGroupID : strAppLabel;
  427.         newRule.AppType = strAppGroupID ? AT_DEFINITION : AT_LABEL;
  428.         newRule.Priority = PRIOR_NORMAL;
  429.  
  430.         if ( !parseBoolean( bUseClientParser ))
  431.             newRule.Priority = ( parseBoolean(bHighPriority) == 1) ? PRIOR_HIGH : PRIOR_LOW;
  432.  
  433.         newRule.Description = strRuleDescription ? strRuleDescription : "";
  434.  
  435.         newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
  436.         newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
  437.         
  438.         // if object does not exist then create it
  439.         if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID) && !parseBoolean(bUseClientParser))
  440.         {
  441.             var definitionList = getDefinitionList(false);
  442.  
  443.             try
  444.             {
  445.                 var definition = definitionList.Get( strRemIpAddrID );
  446.             }
  447.             catch (e)
  448.             {
  449.                 definition = definitionList.CreateDefinition();
  450.  
  451.                 definition.DefinitionID = strRemIpAddrID;
  452.                 definition.ObjectType = OT_FW_IPADDR;
  453.  
  454.                 definitionList.Insert( definition );
  455.             }
  456.         }
  457.  
  458.         newRule.LocIPAddrType = strLocIpAddrID ? RT_DEFINITION : RT_DIRECT;
  459.         newRule.LocIPAddress = strLocIpAddrID ? strLocIpAddrID : (strLocIpAddr ? strLocIpAddr : "*");
  460.         
  461.         // if object does not exist then create it
  462.         if ( strLocIpAddrID && isLDAPSupported() && isLDAPName(strLocIpAddrID) && !parseBoolean(bUseClientParser))
  463.         {
  464.             var definitionList = getDefinitionList(false);
  465.  
  466.             try
  467.             {
  468.                 var definition = definitionList.Get( strLocIpAddrID );
  469.             }
  470.             catch (e)
  471.             {
  472.                 definition = definitionList.CreateDefinition();
  473.  
  474.                 definition.DefinitionID = strLocIpAddrID;
  475.                 definition.ObjectType = OT_FW_IPADDR;
  476.  
  477.                 definitionList.Insert( definition );
  478.             }
  479.         }
  480.  
  481.         newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
  482.         if (strTransportID)
  483.             newRule.TransportID = strTransportID;
  484.         else
  485.             FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  486.  
  487.         newRule.Zone = (eZoneMask ? parseInt(eZoneMask) : 0) ? parseInt(eZoneMask) : (ZI_BIT_SAFE | ZI_BIT_DANGEROUS); // ZI_ALL_ZONES goes to exception here
  488.     
  489.         newRule.Account = iAccount;
  490.  
  491.          newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
  492.         newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
  493.         newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
  494.  
  495.         // rarely used fields
  496.         newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
  497.         newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
  498.         // don't really know the TimeOfDay format....
  499.         newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
  500.         newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
  501.         newRule.Assignment = strUsers ? strUsers : "*";  //newRule.Assignment = (window.external.Context ? Assignment : "*");
  502.         newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
  503.         newRule.Preferred = ( parseBoolean(bPreferred) == 1 ) ? true : false;
  504.         newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
  505.  
  506.         if ( !parseBoolean(bAvoidSavingSDB) )
  507.             SaveParser(bUseClientParser);
  508.  
  509.         return strRuleID;
  510.  
  511.     } catch(e){
  512.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
  513.         return "";
  514.     }
  515. }
  516.  
  517. ///////////////////////////////////////////////////////////////////////
  518. // FW_DeleteRule
  519. function FW_DeleteRule( strRuleID, bUseClientParser, bAvoidSavingSDB )
  520. {
  521.     try {
  522.         var ruleList = FW_getRuleList(bUseClientParser, false);
  523.         var rule = ruleList.Get(strRuleID);
  524.         if (rule)
  525.             ruleList.Remove(rule);
  526.             
  527.         if (parseBoolean(bAvoidSavingSDB)==0)
  528.             SaveParser(bUseClientParser);
  529.             
  530.         return SUCCESS;
  531.     } catch(e){
  532.         return ErrorHandler( ERR_DELETE_FW_RULE_FAILED, STR_DELETE_FW_RULE_FAILED ); 
  533.     }
  534. }
  535.  
  536. ///////////////////////////////////////////////////////////////////////
  537. // FW_AddRoutedRuleImpl - in addition => strInternalIpAddrID, strInternalIpAddr
  538. //   missing - eZoneMask, strAppGroupID, strAppLabel, bIsSystemAccount, bPreferred, bUseClientParser, strUsers
  539. //   returns strRuleID or empty if error
  540. function FW_AddRoutedRuleImpl( strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
  541.     strRemIpAddrID, strRemIpAddr, strInternalIpAddrID, strInternalIpAddr, strIfaceIpAddrID, strIfaceIpAddr, 
  542.     iAccessResult, iAuditLevel,  
  543.     strRuleDescription, bHighPriority, bDisabled, 
  544.     strDayTimeID, strDayTime, 
  545.     iOutConditionAND, iOutConditionOR, eOSVersion, 
  546.     bAvoidSavingSDB )
  547. {
  548.     try {
  549.         var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
  550.         var newRule = ruleList.CreateRule();
  551.         
  552.         // generate the RuleID => must be unique and must maintain server/client syntax
  553.         newRule.RuleID = ruleList.GenerateRuleID( true );
  554.  
  555.         // newRule.RuleIDString is created automatically when newRule.RuleID is set 
  556.         newRule.Priority = (parseBoolean(bHighPriority) != 0) ? PRIOR_HIGH : PRIOR_LOW;
  557.  
  558.         newRule.Description = strRuleDescription ? strRuleDescription : ""; 
  559.         
  560.         newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
  561.         newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*"); 
  562.         
  563.         // if object does not exist then create it
  564.         if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID))
  565.         {
  566.             var definitionList = getDefinitionList(false);
  567.  
  568.             try
  569.             {
  570.                 var definition = definitionList.Get( strRemIpAddrID );
  571.             }
  572.             catch (e)
  573.             {
  574.                 definition = definitionList.CreateDefinition();
  575.  
  576.                 definition.DefinitionID = strRemIpAddrID;
  577.                 definition.ObjectType = OT_FW_IPADDR;
  578.  
  579.                 definitionList.Insert( definition );
  580.             }
  581.         }
  582.  
  583.         newRule.LANIPAddrType = strInternalIpAddrID ? RT_DEFINITION : RT_DIRECT;
  584.         newRule.LANIPAddress = strInternalIpAddrID ? strInternalIpAddrID : (strInternalIpAddr ? strInternalIpAddr : "*"); 
  585.         
  586.         // if object does not exist then create it
  587.         if ( strInternalIpAddrID && isLDAPSupported() && isLDAPName(strInternalIpAddrID))
  588.         {
  589.             var definitionList = getDefinitionList(false);
  590.  
  591.             try
  592.             {
  593.                 var definition = definitionList.Get( strInternalIpAddrID );
  594.             }
  595.             catch (e)
  596.             {
  597.                 definition = definitionList.CreateDefinition();
  598.  
  599.                 definition.DefinitionID = strInternalIpAddrID;
  600.                 definition.ObjectType = OT_FW_IPADDR;
  601.  
  602.                 definitionList.Insert( definition );
  603.             }
  604.         }
  605.  
  606.         if (strIfaceIpAddrID || strIfaceIpAddr)
  607.         {
  608.             newRule.IfaceIPAddrType = strIfaceIpAddrID ? RT_DEFINITION : RT_DIRECT;
  609.             newRule.IfaceIPAddress = strIfaceIpAddrID ? strIfaceIpAddrID : (strIfaceIpAddr ? strIfaceIpAddr : "*"); 
  610.         }
  611.  
  612.         newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
  613.         if (strTransportID) 
  614.             newRule.TransportID = strTransportID;
  615.         else 
  616.             FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  617.  
  618.         newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS; 
  619.         newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
  620.         newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0; 
  621.  
  622.         // rarely used fields
  623.         newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
  624.         newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
  625.         // don't really know the TimeOfDay format....
  626.         newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
  627.         newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
  628.         newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
  629.         newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
  630.  
  631.         var strRuleID = newRule.RuleIDString;
  632.  
  633.         ruleList.Insert(newRule, newRule);
  634.         
  635.         if (parseBoolean(bAvoidSavingSDB)==0)
  636.             SaveParser(false);
  637.             
  638.         return strRuleID;
  639.         
  640.     } catch(e){
  641.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED ); 
  642.         return "";
  643.     }
  644. }
  645.  
  646. function FW_EditRoutedRuleImpl( strRuleID, strTransportID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts,
  647.     strRemIpAddrID, strRemIpAddr, strInternalIpAddrID, strInternalIpAddr, strIfaceIpAddrID, strIfaceIpAddr,
  648.     iAccessResult, iAuditLevel,
  649.     strRuleDescription, bHighPriority, bDisabled,
  650.     strDayTimeID, strDayTime,
  651.     iOutConditionAND, iOutConditionOR, eOSVersion,
  652.     bAvoidSavingSDB )
  653. {
  654.     try {
  655.         var ruleList = FW_getRuleList(false, true);
  656.         var newRule = ruleList.Get(strRuleID);
  657.  
  658.         // newRule.RuleIDString is created automatically when newRule.RuleID is set
  659.         newRule.Priority = (parseBoolean(bHighPriority) != 0) ? PRIOR_HIGH : PRIOR_LOW;
  660.  
  661.         newRule.Description = strRuleDescription ? strRuleDescription : "";
  662.  
  663.         newRule.RemIPAddrType = strRemIpAddrID ? RT_DEFINITION : RT_DIRECT;
  664.         newRule.RemIPAddress = strRemIpAddrID ? strRemIpAddrID : (strRemIpAddr ? strRemIpAddr : "*");
  665.  
  666.         // if object does not exist then create it
  667.         if ( strRemIpAddrID && isLDAPSupported() && isLDAPName(strRemIpAddrID))
  668.         {
  669.             var definitionList = getDefinitionList(false);
  670.  
  671.             try
  672.             {
  673.                 var definition = definitionList.Get( strRemIpAddrID );
  674.             }
  675.             catch (e)
  676.             {
  677.                 definition = definitionList.CreateDefinition();
  678.  
  679.                 definition.DefinitionID = strRemIpAddrID;
  680.                 definition.ObjectType = OT_FW_IPADDR;
  681.  
  682.                 definitionList.Insert( definition );
  683.             }
  684.         }
  685.  
  686.         newRule.LANIPAddrType = strInternalIpAddrID ? RT_DEFINITION : RT_DIRECT;
  687.         newRule.LANIPAddress = strInternalIpAddrID ? strInternalIpAddrID : (strInternalIpAddr ? strInternalIpAddr : "*");
  688.  
  689.         // if object does not exist then create it
  690.         if ( strInternalIpAddrID && isLDAPSupported() && isLDAPName(strInternalIpAddrID))
  691.         {
  692.             var definitionList = getDefinitionList(false);
  693.  
  694.             try
  695.             {
  696.                 var definition = definitionList.Get( strInternalIpAddrID );
  697.             }
  698.             catch (e)
  699.             {
  700.                 definition = definitionList.CreateDefinition();
  701.  
  702.                 definition.DefinitionID = strInternalIpAddrID;
  703.                 definition.ObjectType = OT_FW_IPADDR;
  704.  
  705.                 definitionList.Insert( definition );
  706.             }
  707.         }
  708.  
  709.         newRule.IfaceIPAddrType = strIfaceIpAddrID ? RT_DEFINITION : RT_DIRECT;
  710.         newRule.IfaceIPAddress = strIfaceIpAddrID ? strIfaceIpAddrID : (strIfaceIpAddr ? strIfaceIpAddr : "*");
  711.  
  712.         newRule.TransportType = strTransportID ? RT_DEFINITION : RT_DIRECT;
  713.         if (strTransportID)
  714.             newRule.TransportID = strTransportID;
  715.         else
  716.             FW_SetTransportObjectImpl( newRule.TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  717.  
  718.         newRule.AccessDescriptor.AccessType = AT_NETWORK_ACCESS;
  719.         newRule.AccessDescriptor.AuditLevel = iAuditLevel ? parseInt(iAuditLevel) : 0;
  720.         newRule.AccessDescriptor.AccessResult = iAccessResult ? parseInt(iAccessResult) : 0;
  721.  
  722.         // rarely used fields
  723.         newRule.OutConditionAND = iOutConditionAND ? parseInt(iOutConditionAND) : 0;
  724.         newRule.OutConditionOR = iOutConditionOR ? parseInt(iOutConditionOR) : 0;
  725.         // don't really know the TimeOfDay format....
  726.         newRule.TimeOfDayType = strDayTimeID ? RT_DEFINITION : RT_DIRECT;
  727.         newRule.TimeOfDay = strDayTimeID ? strDayTimeID : (strDayTime ? strDayTime : "");
  728.         newRule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true;
  729.         newRule.OSVersion = eOSVersion ? parseInt(eOSVersion) : OSVER_WIN_ALL;
  730.  
  731.         if (parseBoolean(bAvoidSavingSDB)==0)
  732.             SaveParser(false);
  733.  
  734.         return strRuleID;
  735.  
  736.     } catch(e){
  737.         ErrorHandler( ERR_ADDING_FW_RULE_FAILED, STR_ADDING_FW_RULE_FAILED );
  738.         return "";
  739.     }
  740. }
  741.  
  742. ///////////////////////////////////////////////////////////////////////
  743. // FW_DeleteRoutedRule
  744. function FW_DeleteRoutedRule( strRuleID, bAvoidSavingSDB )
  745. {
  746.     try {
  747.         var ruleList = external.ServerParser(XM_FW).RoutedRuleList; 
  748.         var rule = ruleList.Get(strRuleID);
  749.         if (rule)
  750.             ruleList.Remove(rule);
  751.             
  752.         if ( !parseBoolean(bAvoidSavingSDB) )
  753.             SaveParser( false )
  754.  
  755.         return SUCCESS;
  756.     } catch(e){
  757.         return ErrorHandler( ERR_DELETE_FW_RULE_FAILED, STR_DELETE_FW_RULE_FAILED ); 
  758.     }
  759. }
  760.  
  761. ///////////////////////////////////////////////////////////////////////
  762. // FW_EnableRule
  763. function FW_EnableRule( strRuleID, bDisabled, bUseClientParser, bIsRoutedRule, bAvoidSavingSDB )
  764. {
  765.     try {
  766. /*        alert( strRuleID ) 
  767.         alert( bDisabled )
  768.         alert( bUseClientParser )
  769.         alert( bIsRoutedRule )*/
  770.         
  771.         var ruleList = FW_getRuleList(bUseClientParser, bIsRoutedRule);
  772.         var rule = ruleList.Get(strRuleID);
  773.         
  774.         if (rule)
  775.         {    
  776.             rule.Enabled = ( parseBoolean(bDisabled) == 1 ) ? false : true; //!(parseBoolean(bDisable) != 0);
  777.         }
  778.  
  779.         if ( !parseBoolean(bAvoidSavingSDB) )
  780.             SaveParser(bUseClientParser);
  781.         
  782.         return SUCCESS;
  783.     } catch(e){
  784.         return ErrorHandler( ERR_EDIT_FW_RULE_FAILED, STR_EDIT_FW_RULE_FAILED ); 
  785.     }
  786. }
  787.  
  788. ///////////////////////////////////////////////////////////////////////
  789. // FW_SetTransportObjectImpl - should not be used from html, it is used internally by scripts only
  790. function FW_SetTransportObjectImpl( TransportObject, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts )
  791. {
  792.     var prot = TransportObject;
  793.     prot.Content = "";    // assuming used only in Definitions
  794.     prot.Protocol = eProtocol ? parseInt(eProtocol) : 0;
  795.     prot.Direction = eDirection ? parseInt(eDirection) : 0;
  796.     
  797.     if (PROT_OTHER == prot.Protocol)
  798.     {
  799.         var iProt = 0;
  800.         var iProtFrom = 0;
  801.         var iProtTo = 0;
  802.  
  803.         if ( strCustomProtocolNum.toString().search("-") > -1 )
  804.         {
  805.             var index = strCustomProtocolNum.search("-");
  806.  
  807.             var strProtFrom = strCustomProtocolNum.substring(0,index);
  808.             var strProtTo = strCustomProtocolNum.substring(index + 1);
  809.  
  810.             iProtFrom = parseInt(strProtFrom);
  811.             iProtTo = parseInt(strProtTo);
  812.         }
  813.         else
  814.         {
  815.             iProtFrom = parseInt(strCustomProtocolNum);
  816.             iProtTo = parseInt(strCustomProtocolNum);
  817.         }
  818.         
  819.         iProt = (iProtTo * 65536) + iProtFrom;
  820.     
  821.         prot.CustomProtocolNumber = iProt; //isNaN(parseInt(iCustomProtocolNum)) ? 0 : parseInt(iCustomProtocolNum);
  822.     }
  823.     else if (PROT_ICMP == prot.Protocol )    {
  824.         prot.ICMPType = isNaN(parseInt(eICMPType)) ? 0 : parseInt(eICMPType);
  825.     } else if (PROT_TCP == prot.Protocol || PROT_UDP == prot.Protocol || PROT_TCP_UDP == prot.Protocol || PROT_TCP_S == prot.Protocol)    {
  826.         
  827.         prot.LocalPortFrom = 0;
  828.         prot.LocalPortTo = 0;
  829.         prot.RemotePortFrom = 0;
  830.         prot.RemotePortTo = 0;
  831.         
  832.         if (strLocalPorts)
  833.         {
  834.             if ( strLocalPorts == "*")
  835.                 prot.LocalPortTo = 65535;
  836.             else
  837.             {
  838.                 prot.LocalPortFrom = parseInt(strLocalPorts);
  839.                 var Idx = strLocalPorts.search( "-" );
  840.                 if ((-1) != Idx)
  841.                     prot.LocalPortTo = parseInt( strLocalPorts.substr(Idx+1) );
  842.                 else
  843.                     prot.LocalPortTo = prot.LocalPortFrom;
  844.             }
  845.         } 
  846.         if (strRemotePorts)
  847.         {
  848.             if ( strRemotePorts == "*")
  849.                 prot.RemotePortTo = 65535;
  850.             else
  851.             {
  852.                 prot.RemotePortFrom = parseInt(strRemotePorts);
  853.                 var Idx = strRemotePorts.search( "-" );
  854.                 if ((-1) != Idx)
  855.                     prot.RemotePortTo = parseInt( strRemotePorts.substr(Idx+1) );
  856.                 else
  857.                     prot.RemotePortTo = prot.RemotePortFrom;
  858.             }
  859.         } 
  860.     }
  861. }
  862.  
  863. ///////////////////////////////////////////////////////////////////////
  864. // FW_AddPredefinedProtocolAndPortsObject 
  865. function FW_AddPredefinedProtocolAndPortsObject( strProtAndPortsObjectID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts, bUseClientParser )
  866. {
  867.     try {
  868.         var definitionList = getDefinitionList(bUseClientParser);
  869.         var definition = definitionList.CreateDefinition();
  870.         
  871.         definition.DefinitionID = strProtAndPortsObjectID;
  872.         definition.ObjectType = OT_FW_TRANS;
  873.         
  874.         var newItem = definition.ItemList.CreateItem();
  875.         FW_SetTransportObjectImpl( newItem, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  876.         definition.ItemList.Insert(newItem);
  877.         
  878.         definitionList.Insert( definition );
  879.         
  880.         SaveParser(bUseClientParser);
  881.         
  882.         return SUCCESS;
  883.     }
  884.     catch(e) {
  885.         return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED ); 
  886.     }
  887. }
  888.  
  889. ///////////////////////////////////////////////////////////////////////
  890. // FW_EditPredefinedProtocolAndPortsObject
  891. function FW_EditPredefinedProtocolAndPortsObject( strProtAndPortsObjectID, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts, bUseClientParser )
  892. {
  893.     try {
  894.         var definitionList = getDefinitionList(bUseClientParser);
  895.         var definition = definitionList.Get( strProtAndPortsObjectID );
  896.  
  897.         var itemEnum = new Enumerator(definition.ItemList);
  898.         itemEnum.moveFirst();
  899.         var item = itemEnum.item();
  900.  
  901.         FW_SetTransportObjectImpl( item, eProtocol, strCustomProtocolNum, eDirection, eICMPType, strLocalPorts, strRemotePorts );
  902.         SaveParser(bUseClientParser);
  903.         
  904.         return SUCCESS;
  905.     }
  906.     catch(e) {
  907.         return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED ); 
  908.     }
  909. }
  910.  
  911. ///////////////////////////////////////////////////////////////////////
  912. // FW_DeletePredefinedProtocolAndPortsObject - removes it from FW 
  913. function FW_DeletePredefinedProtocolAndPortsObject( strProtAndPortsObjectID, bUseClientParser )
  914. {
  915.     // remove it from FW database
  916.     try {
  917.           var definitionList = getDefinitionList(bUseClientParser);
  918.         var definition = definitionList.Get( strProtAndPortsObjectID );
  919.         
  920.         if (definition)
  921.             definitionList.Remove(definition);
  922.             
  923.         SaveParser(bUseClientParser);
  924.         
  925.         return SUCCESS;
  926.     }
  927.     catch(e) {
  928.         return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED ); 
  929.     }
  930. }
  931.     
  932. ///////////////////////////////////////////////////////////////////////
  933. // FW_AddPredefinedIPAddressObject
  934. function FW_AddPredefinedIPAddressObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
  935. {
  936.     try {
  937.           var definitionList = getDefinitionList(bUseClientParser);
  938.         var definition = definitionList.CreateDefinition();
  939.         
  940.         definition.DefinitionID = strIPAddressObjectID;
  941.         definition.ObjectType = OT_FW_IPADDR;
  942.  
  943.         
  944.         if (strIPAddress)
  945.         {
  946.         
  947.             var newItem = definition.ItemList.CreateItem();
  948.             newItem.Content = strIPAddress;
  949.             definition.ItemList.Insert(newItem);
  950.         }
  951.         
  952.         definitionList.Insert( definition );
  953.         
  954.         SaveParser(bUseClientParser);
  955.         
  956.         return SUCCESS;
  957.     }
  958.     catch(e) {
  959.         return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED ); 
  960.     }
  961. }
  962.  
  963. ///////////////////////////////////////////////////////////////////////
  964. // FW_DeletePredefinedIPAddressObject 
  965. function FW_DeletePredefinedIPAddressObject( strIPAddressObjectID, bUseClientParser )
  966. {
  967.     // remove it from FW database
  968.     try {
  969.         var definitionList = getDefinitionList(bUseClientParser);
  970.         var definition = definitionList.Get( strIPAddressObjectID );
  971.         
  972.         if (definition)
  973.             definitionList.Remove(definition);
  974.             
  975.         SaveParser(bUseClientParser);
  976.         
  977.         return SUCCESS;
  978.     }
  979.     catch(e) {
  980.         return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED ); 
  981.     }
  982. }
  983.  
  984. ///////////////////////////////////////////////////////////////////////
  985. // FW_AddIPAddressToPredefinedObject
  986. function FW_AddIPAddressToPredefinedObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
  987. {
  988.     try {
  989.           var definitionList = getDefinitionList(bUseClientParser);
  990.         var definition = definitionList.Get( strIPAddressObjectID );
  991.         
  992.         var newItem = definition.ItemList.CreateItem();
  993.         newItem.Content = strIPAddress;
  994.         definition.ItemList.Insert(newItem);
  995.         
  996.         SaveParser(bUseClientParser);
  997.         
  998.         return SUCCESS;
  999.     }
  1000.     catch(e) {
  1001.         return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED ); 
  1002.     }
  1003. }
  1004.  
  1005. ///////////////////////////////////////////////////////////////////////
  1006. // FW_ClearAllIPAddressesFromPredefinedObject
  1007. function FW_ClearAllIPAddressesFromPredefinedObject( strIPAddressObjectID, bUseClientParser )
  1008. {
  1009.     try {
  1010.         var definitionList = getDefinitionList(bUseClientParser);
  1011.         var definition = definitionList.Get( strIPAddressObjectID );
  1012.         
  1013.         definition.ItemList.Clear();
  1014.                 
  1015.         SaveParser(bUseClientParser);
  1016.         
  1017.         return SUCCESS;
  1018.     }
  1019.     catch(e) {
  1020.         return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED ); 
  1021.     }
  1022. }
  1023.  
  1024.  
  1025. ///////////////////////////////////////////////////////////////////////
  1026. // FW_RemoveIPAddressFromPredefinedObject
  1027. function FW_RemoveIPAddressFromPredefinedObject( strIPAddressObjectID, strIPAddress, bUseClientParser )
  1028. {
  1029.     try {
  1030.           var definitionList = getDefinitionList(bUseClientParser);
  1031.         var definition = definitionList.Get( strIPAddressObjectID );
  1032.         
  1033.         var itemEnum = new Enumerator(definition.ItemList);
  1034.         itemEnum.moveFirst();
  1035.                 
  1036.         while (!itemEnum.atEnd())
  1037.         {
  1038.             var item = itemEnum.item();
  1039.             if (item.Content == strIPAddress)
  1040.             {
  1041.                 definition.ItemList.Remove(item);
  1042.                 break;
  1043.             }
  1044.             itemEnum.moveNext();
  1045.         }
  1046.             
  1047.         SaveParser(bUseClientParser);
  1048.         
  1049.         return SUCCESS;
  1050.     }
  1051.     catch(e) {
  1052.         return ErrorHandler( ERR_EDIT_FW_OBJECT_FAILED, STR_EDIT_FW_OBJECT_FAILED ); 
  1053.     }
  1054. }
  1055.  
  1056. ///////////////////////////////////////////////////////////////////////
  1057. // FW_AddRuleTriggerCondition
  1058. function FW_AddRuleTriggerCondition( strRuleID, eCondType, eCondTarget, iBitsOn, iBitsOff, bUseClientParser )
  1059. {
  1060.     try {
  1061.           var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
  1062.         var rule = ruleList.Get( strRuleID );
  1063.         
  1064.         var newConditionSwitch = rule.ConditionSwitchList.CreateConditionSwitch();
  1065.         newConditionSwitch.Type = eCondType;
  1066.         newConditionSwitch.Target = eCondTarget;
  1067.         newConditionSwitch.BitsOn = iBitsOn;
  1068.         newConditionSwitch.BitsOff = iBitsOff;
  1069.         
  1070.         rule.ConditionSwitchList.Insert(newConditionSwitch);
  1071.         
  1072.         SaveParser( false )
  1073.         
  1074.         return SUCCESS;
  1075.     }
  1076.     catch(e) {
  1077.         return ErrorHandler( ERR_ADDING_FW_OBJECT_FAILED, STR_ADDING_FW_OBJECT_FAILED ); 
  1078.     }
  1079. }
  1080.  
  1081. ///////////////////////////////////////////////////////////////////////
  1082. // FW_ClearAllRuleTriggerConditions
  1083. function FW_ClearAllRuleTriggerConditions( strRuleID, bUseClientParser )
  1084. {
  1085.     try {
  1086.         var ruleList = external.ServerParser(XM_FW).RoutedRuleList;
  1087.         var rule = ruleList.Get( strRuleID );
  1088.         
  1089.         rule.ConditionSwitchList.Clear();
  1090.         
  1091.         SaveParser( false );
  1092.         
  1093.         return SUCCESS;
  1094.     }
  1095.     catch(e) {
  1096.         return ErrorHandler( ERR_DELETE_FW_OBJECT_FAILED, STR_DELETE_FW_OBJECT_FAILED ); 
  1097.     }
  1098. }
  1099.  
  1100. ///////////////////////////////////////////////////////////////////////
  1101. // FW_GetPropertyValue 
  1102. function FW_GetPropertyValue( strPropertyID )
  1103. {
  1104.     try {
  1105.         var propList = external.ServerParser(XM_FW).GlobalOptions;
  1106.         var prop = propList.Get( strPropertyID );
  1107.         
  1108.         return prop.Value;
  1109.     } catch(e) {
  1110.         return "";
  1111.     }
  1112. }
  1113.  
  1114. ///////////////////////////////////////////////////////////////////////
  1115. // FW_SetPropertyValue     
  1116. function FW_SetPropertyValue( strPropertyID, Value, eType )
  1117. {
  1118.     var propList = null;
  1119.     try {
  1120.         propList = external.ServerParser(XM_FW).GlobalOptions;
  1121.     } catch(e) {
  1122.         return ErrorHandler( ERR_EDIT_FW_PROPERTY_FAILED, STR_EDIT_FW_PROPERTY_FAILED );
  1123.     }
  1124.  
  1125.     var prop = null;
  1126.     try {
  1127.         prop = propList.Get( strPropertyID );
  1128.     } catch(e) {
  1129.     }
  1130.  
  1131.     try {
  1132.         if (!prop)
  1133.         {
  1134.             prop = propList.CreateProperty();
  1135.             prop.Type = eType;
  1136.             prop.PropertyID = strPropertyID;
  1137.             propList.Insert(prop);
  1138.         }
  1139.         switch ( parseInt(eType) )
  1140.         {
  1141.             case PT_INT:
  1142.                 prop.Value = parseInt(Value);
  1143.                 break;
  1144.             case PT_BOOL:
  1145.                 prop.Value = parseBoolean(Value);
  1146.                 break;
  1147.             default:
  1148.                 prop.Value = Value;
  1149.  
  1150.         }
  1151.         //external.Save();
  1152.         SaveParser( false )
  1153.         
  1154.         return SUCCESS;
  1155.     } catch(e) {
  1156.         return ErrorHandler( ERR_EDIT_FW_PROPERTY_FAILED, STR_EDIT_FW_PROPERTY_FAILED );
  1157.     }
  1158. }
  1159.